From 3904b6cd32e6ca2058f8007546a24ac8f5bf5730 Mon Sep 17 00:00:00 2001 From: "robertlipe@gmail.com" Date: Sat, 21 Jan 2012 23:19:34 +0000 Subject: [PATCH] Add read support for coursepoints to Garmin Training Center format. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4146 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/gtrnctr.c | 60 ++- gpsbabel/reference/track/course~tcx.gpx | 6 +- gpsbabel/reference/track/gtrnctr-readcp.gpx | 220 +++++++++++ gpsbabel/reference/track/gtrnctr-readcp.tcx | 388 ++++++++++++++++++++ gpsbabel/testo.d/classic-4.test | 20 - gpsbabel/testo.d/gtrnctr.test | 23 ++ 6 files changed, 693 insertions(+), 24 deletions(-) create mode 100644 gpsbabel/reference/track/gtrnctr-readcp.gpx create mode 100644 gpsbabel/reference/track/gtrnctr-readcp.tcx create mode 100644 gpsbabel/testo.d/gtrnctr.test diff --git a/gpsbabel/gtrnctr.c b/gpsbabel/gtrnctr.c index f5188279d..f049c6507 100644 --- a/gpsbabel/gtrnctr.c +++ b/gpsbabel/gtrnctr.c @@ -91,9 +91,13 @@ static xg_callback gtc_trk_alt; static xg_callback gtc_trk_hr; static xg_callback gtc_trk_cad; static xg_callback gtc_trk_pwr; +static xg_callback gtc_wpt_crs_s, gtc_wpt_crs_e; static xg_callback gtc_wpt_pnt_s, gtc_wpt_pnt_e; +static xg_callback gtc_wpt_ident; static xg_callback gtc_wpt_lat; static xg_callback gtc_wpt_long; +static xg_callback gtc_wpt_icon; +static xg_callback gtc_wpt_notes; static xg_tag_mapping gtc_map[] = { /* courses tcx v1 & v2 */ @@ -105,9 +109,17 @@ static xg_tag_mapping gtc_map[] = { { gtc_trk_lat, cb_cdata, "/Courses/Course/Track/Trackpoint/Position/LatitudeDegrees" }, { gtc_trk_long, cb_cdata, "/Courses/Course/Track/Trackpoint/Position/LongitudeDegrees" }, { gtc_trk_alt, cb_cdata, "/Courses/Course/Track/Trackpoint/AltitudeMeters" }, - { gtc_trk_alt, cb_cdata, "/Courses/Course/Track/Trackpoint/AltitudeMeters" }, { gtc_trk_hr, cb_cdata, "/Courses/Course/Track/Trackpoint/HeartRateBpm" }, { gtc_trk_cad, cb_cdata, "/Courses/Course/Track/Trackpoint/Cadence" }, + { gtc_wpt_crs_s,cb_start, "/Courses/Course/CoursePoint" }, + { gtc_wpt_crs_e,cb_end, "/Courses/Course/CoursePoint" }, + { gtc_wpt_ident,cb_cdata, "/Courses/Course/CoursePoint/Name"}, + { gtc_trk_utc, cb_cdata, "/Courses/Course/CoursePoint/Time"}, + { gtc_wpt_lat, cb_cdata, "/Courses/Course/CoursePoint/Position/LatitudeDegrees"}, + { gtc_wpt_long, cb_cdata, "/Courses/Course/CoursePoint/Position/LongitudeDegrees"}, + { gtc_trk_alt, cb_cdata, "/Courses/Course/CoursePoint/AltitudeMeters" }, + { gtc_wpt_icon, cb_cdata, "/Courses/Course/CoursePoint/PointType" }, + { gtc_wpt_notes,cb_cdata, "/Courses/Course/CoursePoint/Notes" }, /* history tcx v2 (activities) */ { gtc_trk_s, cb_start, "/Activities/Activity" }, @@ -142,6 +154,7 @@ static xg_tag_mapping gtc_map[] = { { gtc_wpt_pnt_e,cb_end, "/Courses/Course/Lap/BeginPosition" }, { gtc_wpt_lat, cb_cdata, "/Courses/Course/Lap/BeginPosition/LatitudeDegrees" }, { gtc_wpt_long, cb_cdata, "/Courses/Course/Lap/BeginPosition/LongitudeDegrees" }, + { gtc_trk_alt, cb_cdata, "/Courses/Course/Lap/BeginAltitudeMeters" }, { NULL, (xg_cb_type)0, NULL} }; @@ -518,16 +531,40 @@ gtc_trk_pwr(const char* args, const char** unused) wpt_tmp->power = atof(args); } +void +gtc_wpt_crs_s(const char* unused, const char** attrv) +{ + wpt_tmp = waypt_new(); +} + +void +gtc_wpt_crs_e(const char* args, const char** unused) +{ + if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) { + waypt_add(wpt_tmp); + } else { + waypt_free(wpt_tmp); + } + + wpt_tmp = NULL; +} + void gtc_wpt_pnt_s(const char* unused, const char** attrv) { wpt_tmp = waypt_new(); + lap_ct++; } void gtc_wpt_pnt_e(const char* args, const char** unused) { if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) { + /* Add the begin position of a CourseLap as + a waypoint. */ + char *cbuf; + xasprintf(&cbuf, "LAP%03d", lap_ct); + wpt_tmp->shortname = cbuf; waypt_add(wpt_tmp); } else { waypt_free(wpt_tmp); @@ -536,6 +573,14 @@ gtc_wpt_pnt_e(const char* args, const char** unused) wpt_tmp = NULL; } +void +gtc_wpt_ident(const char* args, const char** unused) +{ + wpt_tmp->shortname = xstrdup(args); + /* Set also as notes for compatibility with garmin usb format */ + wpt_tmp->notes = xstrdup(args); +} + void gtc_wpt_lat(const char* args, const char** unused) { @@ -548,6 +593,19 @@ gtc_wpt_long(const char* args, const char** unused) wpt_tmp->longitude = atof(args); } +void +gtc_wpt_icon(const char* args, const char** unused) +{ + wpt_tmp->icon_descr = xstrdup(args); + wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; +} + +void +gtc_wpt_notes(const char* args, const char** unused) +{ + wpt_tmp->description = xstrdup(args); +} + ff_vecs_t gtc_vecs = { ff_type_file, { diff --git a/gpsbabel/reference/track/course~tcx.gpx b/gpsbabel/reference/track/course~tcx.gpx index 5fcf3435e..49de3f3a9 100644 --- a/gpsbabel/reference/track/course~tcx.gpx +++ b/gpsbabel/reference/track/course~tcx.gpx @@ -8,9 +8,9 @@ - WPT001 - WPT001 - WPT001 + LAP001 + LAP001 + LAP001 ThursRide diff --git a/gpsbabel/reference/track/gtrnctr-readcp.gpx b/gpsbabel/reference/track/gtrnctr-readcp.gpx new file mode 100644 index 000000000..fe6d93fbc --- /dev/null +++ b/gpsbabel/reference/track/gtrnctr-readcp.gpx @@ -0,0 +1,220 @@ + + + + + + LAP001 + LAP001 + LAP001 + + + 231.000000 + + Tp Gen + Not Gen + Tp Gen + Generic + + + 232.000000 + + Tp Sum + Not Sum + Tp Sum + Summit + + + 232.000000 + + Tp Val + Not Val + Tp Val + Valley + + + 232.000000 + + Tp Wat + Not Wat + Tp Wat + Water + + + 232.000000 + + Tp Foo + Not Foo + Tp Foo + Food + + + 232.000000 + + Tp Dan + Not Dan + Tp Dan + Danger + + + 234.000000 + + Tp Lef + Not Lef + Tp Lef + Left + + + 233.000000 + + Tp Rig + Not Rig + Tp Rig + Right + + + 233.000000 + + Tp Str + Not Str + Tp Str + Straight + + + 233.000000 + + Tp Fir + Not Fir + Tp Fir + First Aid + + + 230.000000 + + Tp 4th + Not 4th + Tp 4th + 4th Category + + + 228.000000 + + Tp 3th + Not 3rd + Tp 3th + 3rd Category + + + 224.000000 + + Tp 2nd + Not 2nd + Tp 2nd + 2nd Category + + + 224.000000 + + Tp 1st + Not 1st + Tp 1st + 1st Category + + + 226.000000 + + Tp Hor + Not Hor + Tp Hor + Hors Category + + + 225.000000 + + Tp Spr + Not Spr + Tp Spr + Sprint + + + Test CP Reading + + + 231.000000 + + + + 231.000000 + + + + 231.000000 + + + + 232.000000 + + + + 232.000000 + + + + 232.000000 + + + + 232.000000 + + + + 232.000000 + + + + 234.000000 + + + + 233.000000 + + + + 233.000000 + + + + 233.000000 + + + + 230.000000 + + + + 228.000000 + + + + 224.000000 + + + + 224.000000 + + + + 226.000000 + + + + 225.000000 + + + + + diff --git a/gpsbabel/reference/track/gtrnctr-readcp.tcx b/gpsbabel/reference/track/gtrnctr-readcp.tcx new file mode 100644 index 000000000..f09771c1d --- /dev/null +++ b/gpsbabel/reference/track/gtrnctr-readcp.tcx @@ -0,0 +1,388 @@ + + + + + + + Test CP Reading + + + + + + + Test CP Reading + + 309.9 + 207.872342345229 + + 28.3899562951997 + -16.5815234184265 + + + 28.3897769635538 + -16.5820491313934 + + Active + + + + + + 28.389956 + -16.581523 + + 231 + 0 + Absent + + + + + 28.389950 + -16.581551 + + 231 + 2.78552429082476 + Absent + + + + + 28.389900 + -16.581539 + + 231 + 8.46401259709588 + Absent + + + + + 28.389919 + -16.581369 + + 232 + 25.2160839556801 + Absent + + + + + 28.390003 + -16.581287 + + 232 + 37.536598150474 + Absent + + + + + 28.389985 + -16.581202 + + 232 + 46.1852716217043 + Absent + + + + + 28.390003 + -16.581105 + + 232 + 55.8547825200545 + Absent + + + + + 28.389994 + -16.581019 + + 232 + 64.3105241299902 + Absent + + + + + 28.389900 + -16.581051 + + 234 + 75.26038211514 + Absent + + + + + 28.389909 + -16.581191 + + 233 + 88.9351471352528 + Absent + + + + + 28.389890 + -16.581309 + + 233 + 100.661161922849 + Absent + + + + + 28.389871 + -16.581438 + + 233 + 113.420447740461 + Absent + + + + + 28.389881 + -16.581663 + + 230 + 135.470349678032 + Absent + + + + + 28.389852 + -16.581813 + + 228 + 150.486980256282 + Absent + + + + + 28.389815 + -16.581985 + + 224 + 167.78435337889 + Absent + + + + + 28.389834 + -16.582156 + + 224 + 184.695864453439 + Absent + + + + + 28.389768 + -16.582199 + + 226 + 193.151621872271 + Absent + + + + + 28.389777 + -16.582049 + + 225 + 207.872342345229 + Absent + + + + Tp Gen + + + 28.389956 + -16.581523 + + 231 + Generic + Not Gen + + + Tp Sum + + + 28.389919 + -16.581369 + + 232 + Summit + Not Sum + + + Tp Val + + + 28.390003 + -16.581287 + + 232 + Valley + Not Val + + + Tp Wat + + + 28.389985 + -16.581202 + + 232 + Water + Not Wat + + + Tp Foo + + + 28.390003 + -16.581105 + + 232 + Food + Not Foo + + + Tp Dan + + + 28.389994 + -16.581019 + + 232 + Danger + Not Dan + + + Tp Lef + + + 28.389900 + -16.581051 + + 234 + Left + Not Lef + + + Tp Rig + + + 28.389909 + -16.581191 + + 233 + Right + Not Rig + + + Tp Str + + + 28.389890 + -16.581309 + + 233 + Straight + Not Str + + + Tp Fir + + + 28.389871 + -16.581438 + + 233 + First Aid + Not Fir + + + Tp 4th + + + 28.389881 + -16.581663 + + 230 + 4th Category + Not 4th + + + Tp 3th + + + 28.389852 + -16.581813 + + 228 + 3rd Category + Not 3rd + + + Tp 2nd + + + 28.389815 + -16.581985 + + 224 + 2nd Category + Not 2nd + + + Tp 1st + + + 28.389834 + -16.582156 + + 224 + 1st Category + Not 1st + + + Tp Hor + + + 28.389768 + -16.582199 + + 226 + Hors Category + Not Hor + + + Tp Spr + + + 28.389777 + -16.582049 + + 225 + Sprint + Not Spr + + + + diff --git a/gpsbabel/testo.d/classic-4.test b/gpsbabel/testo.d/classic-4.test index abeaa070b..a85b1e2b2 100755 --- a/gpsbabel/testo.d/classic-4.test +++ b/gpsbabel/testo.d/classic-4.test @@ -230,26 +230,6 @@ rm -f ${TMPDIR}/itracku.unicsv gpsbabel -w -i itracku-bin -f ${REFERENCE}/itracku.dat -o unicsv,utc=0 -F ${TMPDIR}/itracku.unicsv compare ${REFERENCE}/itracku.unicsv ${TMPDIR}/itracku.unicsv -# -# Garmin Tranining Center .tcx (gtrnctr) -# -# reading -rm -f ${TMPDIR}/history~tcx.csv ${TMPDIR}/course~tcx.csv -gpsbabel -i gtrnctr -f ${REFERENCE}/track/history.tcx -t -o unicsv,utc=0 -F ${TMPDIR}/history~tcx.csv -compare ${REFERENCE}/track/history~tcx.csv ${TMPDIR}/history~tcx.csv -gpsbabel -i gtrnctr -f ${REFERENCE}/track/history.tcx -t -o gpx -F ${TMPDIR}/history~tcx.gpx -compare ${REFERENCE}/track/history~tcx.gpx ${TMPDIR}/history~tcx.gpx -gpsbabel -i gtrnctr -f ${REFERENCE}/track/course.tcx -t -o unicsv,utc=0 -F ${TMPDIR}/course~tcx.csv -compare ${REFERENCE}/track/course~tcx.csv ${TMPDIR}/course~tcx.csv -gpsbabel -i gtrnctr -f ${REFERENCE}/track/course.tcx -t -o gpx -F ${TMPDIR}/course~tcx.gpx -compare ${REFERENCE}/track/course~tcx.gpx ${TMPDIR}/course~tcx.gpx -# writing -rm -f ${TMPDIR}tcxtest~gpx-course.tcx ${TMPDIR}tcxtest~gpx-history.tcx -gpsbabel -i gpx -f ${REFERENCE}/track/tcxtest.gpx -o gtrnctr,course=1 -F ${TMPDIR}/tcxtest~gpx-course.tcx -compare ${REFERENCE}/track/tcxtest~gpx-course.tcx ${TMPDIR}/tcxtest~gpx-course.tcx -gpsbabel -i gpx -f ${REFERENCE}/track/tcxtest.gpx -o gtrnctr,course=0 -F ${TMPDIR}/tcxtest~gpx-history.tcx -compare ${REFERENCE}/track/tcxtest~gpx-history.tcx ${TMPDIR}/tcxtest~gpx-history.tcx - # # Memory-Map Navigator overlay files (.mmo) # diff --git a/gpsbabel/testo.d/gtrnctr.test b/gpsbabel/testo.d/gtrnctr.test new file mode 100644 index 000000000..082f72280 --- /dev/null +++ b/gpsbabel/testo.d/gtrnctr.test @@ -0,0 +1,23 @@ +# +# Garmin Tranining Center .tcx (gtrnctr) +# +# reading +rm -f ${TMPDIR}/history~tcx.csv ${TMPDIR}/course~tcx.csv +gpsbabel -i gtrnctr -f ${REFERENCE}/track/history.tcx -t -o unicsv,utc=0 -F ${TMPDIR}/history~tcx.csv +compare ${REFERENCE}/track/history~tcx.csv ${TMPDIR}/history~tcx.csv +gpsbabel -i gtrnctr -f ${REFERENCE}/track/history.tcx -t -o gpx -F ${TMPDIR}/history~tcx.gpx +compare ${REFERENCE}/track/history~tcx.gpx ${TMPDIR}/history~tcx.gpx +gpsbabel -i gtrnctr -f ${REFERENCE}/track/course.tcx -t -o unicsv,utc=0 -F ${TMPDIR}/course~tcx.csv +compare ${REFERENCE}/track/course~tcx.csv ${TMPDIR}/course~tcx.csv +gpsbabel -i gtrnctr -f ${REFERENCE}/track/course.tcx -t -o gpx -F ${TMPDIR}/course~tcx.gpx +compare ${REFERENCE}/track/course~tcx.gpx ${TMPDIR}/course~tcx.gpx +# writing +rm -f ${TMPDIR}tcxtest~gpx-course.tcx ${TMPDIR}tcxtest~gpx-history.tcx +gpsbabel -i gpx -f ${REFERENCE}/track/tcxtest.gpx -o gtrnctr,course=1 -F ${TMPDIR}/tcxtest~gpx-course.tcx +compare ${REFERENCE}/track/tcxtest~gpx-course.tcx ${TMPDIR}/tcxtest~gpx-course.tcx +gpsbabel -i gpx -f ${REFERENCE}/track/tcxtest.gpx -o gtrnctr,course=0 -F ${TMPDIR}/tcxtest~gpx-history.tcx +compare ${REFERENCE}/track/tcxtest~gpx-history.tcx ${TMPDIR}/tcxtest~gpx-history.tcx + +# Reading coursepoints +gpsbabel -i gtrnctr -f ${REFERENCE}/track/gtrnctr-readcp.tcx -o gpx -F ${TMPDIR}/tcxtest-readcp.gpx +compare ${REFERENCE}/track/gtrnctr-readcp.gpx ${TMPDIR}/tcxtest-readcp.gpx -- 2.30.2